package com.babasport.web.utils;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

/**
 * 运用Filter来解决中文问题(统一编码为UTF-8)
 * @author Administrator
 *
 */
public class CodeFilter implements Filter {

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse rsp,
			FilterChain fc) throws IOException, ServletException {
		HttpServletRequest httpReq = (HttpServletRequest) req;
		httpReq.setCharacterEncoding("UTF-8");//将请求统一编码为UTF-8
		fc.doFilter(req, rsp);
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}

}
